package com.ruoyi.quartz.task;

import com.ruoyi.common.core.domain.vo.SysUserVO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysPersonnelClock;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysPersonnelClockService;

import java.util.ArrayList;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {

    @Autowired
    private ISysPersonnelClockService sysPersonnelClockService;

    @Autowired
    private ISysUserService userService;


    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }


    public void ryNoParams()
    {
        //每天凌晨1点执行打卡状态更新
        sysPersonnelClockService.updateCurrentDateClocks();
        //执行新增一天空打卡数据
        List<SysPersonnelClock> clocks = new ArrayList<SysPersonnelClock>();
        List<SysUserVO> sysUserVOList = userService.selectUserVO();
        for (SysUserVO sysUserVO : sysUserVOList) {
            clocks.add(new SysPersonnelClock(DateUtils.getNextDate(1),DateUtils.getWeek(DateUtils.getNextDate(1)),sysUserVO.getUserId(),sysUserVO.getTenantId()));
        }
        //批量插入
        sysPersonnelClockService.batchInsertClock(clocks);
    }

}
